﻿
@{
    Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>导入基本数据</title>
    <link href="~/Content/style.css" rel="stylesheet" type="text/css" />
    <style>
        input[type='file']{
            opacity:0;
            position:absolute;
            left:0;
            top:0;
        }
        ul li a{
            text-align:center;
        }
        ul li a label{
            display:block;
        }
    </style>
</head>

<body>
    @Html.Action("Top", "Home")
    <div class="clear"></div>
    <div id="daoru">
        <h2>导入基本数据</h2>
        <ul>
            <li><a href="javascript:;" class="dr"><label for="ipt_raw">原材料及价格定义</label><input id="ipt_raw" type="file" onchange="onUpload(this, 1);" accept="application/vnd.ms-excel"/></a><a href="/Templates/原材料及价格定义模板.xls" class="mb">原材料及价格定义模板</a></li>
            <li><a href="javascript:;" class="dr"><label for="ipt_gx">工序名称及加工单价设置</label><input id="ipt_gx" type="file" onchange="onUpload(this, 2);" accept="application/vnd.ms-excel" /></a><a href="/Templates/工序名称及加工单价设置模板.xls" class="mb">工序名称及加工单价设置模板</a></li>
            <li><a href="javascript:;" class="dr"><label for="ipt_rm">外购件信息库清单</label><input id="ipt_rm" type="file" onchange="onUpload(this, 3);" accept="application/vnd.ms-excel" /></a><a href="/Templates/外购件信息库清单模板.xls" class="mb">外购件信息库清单模板</a></li>
            <li><a href="javascript:;" class="dr"><label for="ipt_gy">工艺工序术语表</label><input id="ipt_gy" type="file" onchange="onUpload(this, 4);" accept="application/vnd.ms-excel" /></a><a href="/Templates/工艺工序术语表模板.xls" class="mb">工艺工序术语表模板</a></li>
            <li><a href="javascript:;" class="dr"><label for="ipt_pd">批量导入产品</label><input id="ipt_pd" type="file" onchange="onUpload(this, 5);" accept="application/vnd.ms-excel" /></a><a href="/Templates/导入产品表模板.xls" class="mb">导入产品表模板</a></li>
        </ul>
        <div class="clear"></div>
        <p>提示：基础资料导入的主要功能是：将事先以Excel编辑好的固定格式导入到系统相应的资料档案中，请严格按照上方的样例格式进行编辑后导入，如格式不同，则会发生数据导入错误！</p>
    </div>
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/menu.js"></script>
    <script src="~/Scripts/uilts.js"></script>
    <script>
        function onUpload(obj,type) {
            if (obj.files.length == 0)
                return;
            if(typeof(window.FormData) == undefined){
                alert("浏览器版本过低，请使用高版本浏览器!");
                return;
            }
            if (obj.files[0].type!="" && obj.files[0].type != "application/vnd.ms-excel") {
                alert("暂时只支持office excel 2003文件(文件后缀.xls)!");
                return;
            }
            var data = new FormData();
            data.append("file", obj.files[0]);
            PostFile("/ImportData/Upload", data, function (result) {
                if (result.code == 0) {
                    //开始解析
                    if (result.data != undefined && result.data != "") {
                        //todo anysis
                        var pdata = { file:result.data,type:type};
                        PostApi("/ImportData/AnalyseData", pdata, function (result) {
                            if (result.code == 0) {
                                if (result.ErrorMessage != undefined && result.ErrorMessage != "")
                                    alert(result.ErrorMessage);
                                else
                                    alert("文件解析成功!");
                            } else {
                                alert(result.ErrorMessage);
                            }
                        }, function () {
                            alert("文件解析失败!");
                        });
                    } else {
                        alert("文件上传失败!");
                    }
                } else {
                    alert(result.ErrorMessage);
                }
            }, function () {
                alert("文件上传失败!");
            });
        }
    </script>
</body>
</html>
